/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2009 - 2012 Luca Mingardi.
 *
 * This file is part of jeeObserver.
 *
 * JeeObserver is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * JeeObserver is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package jeeobserver.server.settings;

import jeeobserver.HardDiskObserver;
import jeeobserver.server.settings.Condition.NumberCondition;
import jeeobserver.server.settings.Condition.SizeCondition;
import jeeobserver.server.settings.Condition.TextCondition;

/**
 * The Class HardDiskExclusionRule.
 *
 * @author Luca Mingardi
 * @version 4.0
 */
public class HardDiskExclusionRule extends Rule {

	 /** The Constant serialVersionUID. */
	 private static final long serialVersionUID = 40L;

	 /** The path condition. */
	 private TextCondition pathCondition;

	 /** The free size condition. */
	 private SizeCondition freeSizeCondition;

	 /** The usage percentage condition. */
	 private NumberCondition usagePercentageCondition;

	 public boolean isObserverInRule(HardDiskObserver observer) {

			if (super.isObserverInRule(observer)) {

				 if ((this.getPathCondition() == null) || this.getPathCondition().checkValue(observer.getPath())) {
						if ((this.getFreeSizeCondition() == null) || this.getFreeSizeCondition().checkByteValue(observer.getFreeBytes())) {
							 double usagePercentage = 0;
							 if (observer.getTotalBytes() > 0) {
									usagePercentage = (observer.getUsedBytes() / observer.getTotalBytes()) * 100;
							 }
							 if ((this.getUsagePercentageCondition() == null) || this.getUsagePercentageCondition().checkValue(usagePercentage)) {
									return true;
							 }

						}
				 }
			}
			return false;
	 }

	 /**
	  * Gets the path condition.
	  *
	  * @return the path condition
	  */
	 public TextCondition getPathCondition() {
			return this.pathCondition;
	 }

	 /**
	  * Sets the path condition.
	  *
	  * @param pathCondition the new path condition
	  */
	 public void setPathCondition(TextCondition pathCondition) {
			this.pathCondition = pathCondition;
	 }

	 /**
	  * Gets the free size condition.
	  *
	  * @return the free size condition
	  */
	 public SizeCondition getFreeSizeCondition() {
			return this.freeSizeCondition;
	 }

	 /**
	  * Sets the free size condition.
	  *
	  * @param freeSizeCondition the new free size condition
	  */
	 public void setFreeSizeCondition(SizeCondition freeSizeCondition) {
			this.freeSizeCondition = freeSizeCondition;
	 }

	 /**
	  * Gets the usage percentage condition.
	  *
	  * @return the usage percentage condition
	  */
	 public NumberCondition getUsagePercentageCondition() {
			return this.usagePercentageCondition;
	 }

	 /**
	  * Sets the usage percentage condition.
	  *
	  * @param usagePercentageCondition the new usage percentage condition
	  */
	 public void setUsagePercentageCondition(NumberCondition usagePercentageCondition) {
			this.usagePercentageCondition = usagePercentageCondition;
	 }
}
